using System.IO;
using C3.XNA;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using RpgXna.Model.SpriteBase;

namespace RpgXna.Model.Entities
{
    public class PickableObject : CollidableSprite, IEnvironment
    {
        private readonly int _id;
        private readonly string _resName;

        private Texture2D _textureMin;

        public PickableObject(int id, int x, int y, string resName, string name, string description)
        {
            _id = id;
            _resName = resName;
            Name = name;
            Description = description;
            Position = new Vector2(x, y);
            Rotation = 0f;
            Speed = Vector2.Zero;
            Direction = Vector2.Zero;
        }

        public string Description { get; private set; }

        public string Name { get; private set; }

        public Texture2D TextureMin
        {
            get { return _textureMin; }
        }
        #region IEnvironment Members

        public int Id
        {
            get { return _id; }
        }

        public void Draw(SpriteBatch sb)
        {
            sb.Draw(Texture, Position, null, Color.White, Rotation, Origin, Scale, SpriteEffects.None, 0);
            sb.DrawRectangle(Box, Color.Red, 2);
        }

        public void Load(ContentManager cm)
        {
            LoadTexture(cm.Load<Texture2D>(_resName));
            var dir = new DirectoryInfo(cm.RootDirectory);
            string minFile = _resName + "_min";

            foreach (FileInfo f in dir.GetFiles())
            {
                string file = Path.GetFileNameWithoutExtension(f.Name);
                if (file != null && file.Contains(minFile))
                {
                    _textureMin = cm.Load<Texture2D>(minFile);
                    break;
                }
            }
        }

        public void Update()
        {
        }

        #endregion IEnvironment Members
    }
}